﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
using System.Windows;
using System.Numerics;

namespace Zero.UControl.Base.Helper.Base
{
    internal class ScaleCommand : IDrawingCommand
    {
        private readonly UIElement _el;
        private readonly double _f;
        private readonly DrawingTool _tool;

        public ScaleCommand(UIElement el, double f, DrawingTool tool)
        {
            _el = el;
            _f = f;
            _tool = tool;
        }

        private ScaleTransform? _st;
        public void Execute()
        {
            _st = _el.RenderTransform as ScaleTransform ?? new ScaleTransform(1, 1);
            double newX = _st.ScaleX * _f;
            double newY = _st.ScaleY * _f;
            if (newX < _tool.MinScale || newX > _tool.MaxScale) return; // 超界直接忽略
            _el.RenderTransform = _st;
            _st.ScaleX = newX;
            _st.ScaleY = newY;
        }
        public void UnExecute()
        {
            if (_st != null)
            {
                _st.ScaleX /= _f;
                _st.ScaleY /= _f;
            }
        }
    }
}
